<!doctype html>

<html>

<head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

  <title>Basis Demos: Tables</title>

  <link rel="stylesheet" type="text/css" title="Compat Style" href="../../style/table/vista/style.css" media="screen" />
  <link rel="stylesheet" type="text/css" title="Compat Style" href="../../style/scrolltable/vista/style.css" media="screen" />
  <link rel="stylesheet" type="text/css" title="Compat Style" href="../../style/resizer/default/style.css" media="screen" />

  <style type="text/css" id="demo-css">
    HTML,
    BODY
    {
      font-size: small;
      font-family: Tahoma, Verdana, Arial, sans-serif;
    }

    .DemoBlock
    {
      border: 1px solid #D0D0D0;
        -moz-border-radius: 3px;
        -webkit-border-radius: 3px;
      border-radius: 3px;
      padding: 15px;
      margin: 0 0 .5em 10px;
      overflow: hidden;
      position: relative;
      width: 45%;
      float: left;
    }
    .DemoBlock H2
    {
      font-size: 80%;
      font-weight: normal;
      background: #EEE;
      margin: -15px -15px 10px -15px;
      padding: 2px;
      text-align: center;
    }
    .scrollTableContainer
    {
      height: 300px;
      position: relative;
    }
    TD
    {
      white-space: nowrap;
    }

  </style>
  <!--[if lt IE 7]>
  <style type="text/css">
    BODY
    {
      font-size: x-small;
    }
  </style>
  <![endif]-->

  <!--[if IE 7]>
  <![endif]-->


  <script type="text/javascript" src="../../basis-all.js"></script>

  <script type="text/javascript" src="../demo.js"></script>
</head>

<body>
  <h1>Basic demos: Tables</h1>
  
  <p id="demo-summary">
    ..
  </p>
  <div id="demo-description">
    ..
  </div>

  <div id="demo-container"></div>

  <script type="text/javascript" id="demo-javascript">

    basis.require('basis.dom');
    basis.require('basis.date');
    basis.require('basis.ui.table');
    
    // import names

    var getter = Function.getter;
    var DOM = basis.dom;
    var Table = basis.ui.table.Table;
    var ScrollTable = basis.ui.scrolltable.ScrollTable;

    //
    // Main part
    //

    function createBlock(header){
      return DOM.insert(DOM.get('demo-container'), DOM.createElement('.DemoBlock', DOM.createElement('H2', header)));
    }

    var data = [
      ['3m Co',                               71.72, 0.02,  0.03,  '2010/9/1 12:00'],
      ['Alcoa Inc',                           29.01, 0.42,  1.47,  '2010/9/1 12:00'],
      ['Altria Group Inc',                    83.81, 0.28,  0.34,  '2010/9/1 12:00'],
      ['American Express Company',            52.55, 0.01,  0.02,  '2010/9/1 12:00'],
      ['American International Group, Inc.',  64.13, 0.31,  0.49,  '2010/9/1 12:00'],
      ['AT&T Inc.',                           31.61, -0.48, -1.54, '2010/9/1 12:00'],
      ['Boeing Co.',                          75.43, 0.53,  0.71,  '2010/9/1 12:00'],
      ['Caterpillar Inc.',                    67.27, 0.92,  1.39,  '2010/9/1 12:00'],
      ['Citigroup, Inc.',                     49.37, 0.02,  0.04,  '2010/9/1 12:00'],
      ['E.I. du Pont de Nemours',             40.48, 0.51,  1.28,  '2010/9/1 12:00'],
      ['Exxon Mobil Corp',                    68.1,  -0.43, -0.64, '2010/9/1 12:00'],
      ['General Electric Company',            34.14, -0.08, -0.23, '2010/9/1 12:00'],
      ['General Motors Corporation',          30.27, 1.09,  3.74,  '2010/9/1 12:00'],
      ['Hewlett-Packard Co.',                 36.53, -0.03, -0.08, '2010/9/1 12:00'],
      ['Honeywell Intl Inc',                  38.77, 0.05,  0.13,  '2010/9/1 12:00'],
      ['Intel Corporation',                   19.88, 0.31,  1.58,  '2010/9/1 12:00'],
      ['International Business Machines',     81.41, 0.44,  0.54,  '2010/9/1 12:00'],
      ['Johnson & Johnson',                   64.72, 0.06,  0.09,  '2010/9/1 12:00'],
      ['JP Morgan & Chase & Co',              45.73, 0.07,  0.15,  '2010/9/1 12:00'],
      ['McDonald\'s Corporation',             36.76, 0.86,  2.40,  '2010/9/1 12:00'],
      ['Merck & Co., Inc.',                   40.96, 0.41,  1.01,  '2010/9/1 12:00'],
      ['Microsoft Corporation',               25.84, 0.14,  0.54,  '2010/9/1 12:00'],
      ['Pfizer Inc',                          27.96, 0.4,   1.45,  '2010/9/1 12:00'],
      ['The Coca-Cola Company',               45.07, 0.26,  0.58,  '2010/9/1 12:00'],
      ['The Home Depot, Inc.',                34.64, 0.35,  1.02,  '2010/9/1 12:00'],
      ['The Procter & Gamble Company',        61.91, 0.01,  0.02,  '2010/9/1 12:00'],
      ['United Technologies Corporation',     63.26, 0.55,  0.88,  '2010/9/1 12:00'],
      ['Verizon Communications',              35.57, 0.39,  1.11,  '2010/9/1 12:00'],
      ['Wal-Mart Stores, Inc.',               45.45, 0.73,  1.63,  '2010/9/1 12:00']
    ].map(function(row){
      return {
        data: {
          title: row[0],
          price: row[1],
          change: row[2],
          percentChange: row[3],
          lastUpdate: new Date(row[4])
        }
      }
    });

    new Table({
      container: createBlock('table'),
      structure: [
        { header: 'Company', body: Function.getter('data.title'), sorting: Function.getter('data.title'), autosorting: true },
        { header: 'Price', body: Function.getter('data.price', '${0:.2}'), autosorting: true, sorting: Function.getter('data.price') },
        { header: 'Change', body: Function.getter('data.change', '{0:.2}') },
        { header: '% Change', body: Function.getter('data.percentChange', '{0:.2}%') },
        { header: 'Last Updated', body: Function.getter('data.lastUpdate.toFormat("%M/%D/%Y")') }
      ],
      childNodes: data
    });

    basis.dom.event.onLoad(function(){
      container = createBlock('basis.ui.scrolltable.ScrollTable fit to container').appendChild(basis.dom.createElement('.scrollTableContainer'));
      table = new ScrollTable({
        selection: {multiple:true},
        //container: container,
        cssClassName: 'FitToContainer',
        header: { grouping: Function.getter('groupId') },
        structure: [
          { groupId: 2, header: 'Company', body: Function.getter('data.title'), sorting: Function.getter('data.title') },
          { header: 'Price', body: Function.getter('data.price', '${0:.2}'), sorting: Function.getter('data.price'), footer: { content: 'footer' } },
          { header: 'Change', body: Function.getter('data.change', '{0:.2}') },
          { header: '% Change', body: Function.getter('data.percentChange', '{0:.2}%') },
          { header: 'Last Updated', body: Function.getter('data.lastUpdate.toFormat("%M/%D/%Y")') }
        ],
        childNodes: data
      }); 
      /*setTimeout(function(){
        table.setChildNodes(data);
      }, 10);*/
      basis.dom.insert(container, table.element);

      var r = new basis.ui.resizer.Resizer({ element: container.parentNode });
      basis.cssom.setStyle(r.resizer, {
        height: '100%',
        width: '5px',
        top: 0,
        right: 0
      });


      var container2 = createBlock('basis.ui.scrolltable.ScrollTable');
      table2 = new ScrollTable({
        container: container2,
        header: { grouping: Function.getter('groupId') },
        structure: [
          { groupId: 2, header: 'Company', body: Function.getter('data.title'), sorting: Function.getter('data.title') },
          { header: 'Price', body: Function.getter('data.price', '${0:.2}'), sorting: Function.getter('data.price'), footer: 'xxx' },
          { header: 'Change', body: Function.getter('data.change', '{0:.2}') },
          { header: '% Change', body: Function.getter('data.percentChange', '{0:.2}%') },
          { header: 'Last Updated', body: Function.getter('data.lastUpdate.toFormat("%M/%D/%Y")') }
        ],
        childNodes: data
      }); 

    })

    basis.dom.insert('demo-container', basis.dom.createElement('button', 'remove')).onclick = function(){
      basis.dom.remove(table.element);
    };
    basis.dom.insert('demo-container', basis.dom.createElement('button', 'insert')).onclick = function(){
      basis.dom.insert(container, table.element);
    };



  </script>
</body>

</html>